import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-07
 * Time: 13:24
 */
public class MyThreadPoolExecutor {
    private final int capacity = 1000;
    //阻塞队列
    private final MyBlockingQueue queue = new MyBlockingQueue(capacity);
    private final List<Thread> list = new ArrayList<>();
    //创建线程
    public MyThreadPoolExecutor(int n){
        for (int i = 0; i < n; i++) {
            Thread thread = new Thread(()->{
                while (true) {
                    try {
                        queue.take().run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            thread.start();
            list.add(thread);
        }
    }
    //添加任务
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
    public int getCapacity(){
        return capacity;
    }
    //获取线程
    public List<Thread> getList() {
        return list;
    }
}
